import axios from 'axios'

const service = axios.create({
    baseURL: 'https://ys.gcrong.com',
    timeout: 5000
})

service.interceptors.request.use(
    (config) => {
        return config
    },
    (error) => {
        console.log(error)
        return Promise.reject(error)
    }
)

service.interceptors.response.use(
    (response) => {
        const res = response.data
        if (res.code !== 200) {
            return Promise.reject(new Error(res.msg || '网络异常，请稍后~'))
        } else {
            return res
        }
    },
    (error) => {
        return Promise.reject(error)
    }
)

export default service
